package com.sheep.jucdemo.part1.part1_7;

/**
 * @Date 2022/4/6 22:04
 * @Created by sheep
 */
public class Test1_7_2 {

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("threadOne begin sleep 2000 seconds");
                    Thread.sleep(200000);
                    System.out.println("threadOne awaking");
                } catch (InterruptedException e) {
                    System.out.println("threadOne is interrupted while sleeping");
                    return;
                }
                System.out.println("threadOne-leaving normally");
            }
        });
        // 启动子线程
        threadOne.start();
        // 确保子线程进入sleep
        Thread.sleep(1000);
        // 打断子线程休眠，让子线程从sleep函数返回
        threadOne.interrupt();
        // 等待子线程执行完毕
        threadOne.join();
        System.out.println("main thread is over");
    }
}
